import axios from './axios'
import qs from 'qs'
import {
    baseUrl
} from '@/config/config'

/**
 * 代理配置列表
 * @param {*} params 
 * @returns 
 */
 export const getSysConfig = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/agent/config',
            method: 'get'
        }).then(res => {
            resolve(res.data)
        }).catch(error => {
            reject(error)
        })
    })
}

/**
 * 代理配置列表下拉
 * @param {*} params 
 * @returns 
 */
 export const getSysConfigSelect = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/agent/config/list',
            method: 'get'
        }).then(res => {
            resolve(res.data)
        }).catch(error => {
            reject(error)
        })
    })
}

/**
 * 新增代理配置
 * @param {*} params 
 * @returns 
 */
 export const addSysConfig = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/agent/config',
            method: 'POST',
            data: params
        }).then(res => {
            resolve(res.data)
        }).catch(error => {
            reject(error)
        })
    })
}

/**
 * 编辑代理配置
 * @param {*} params 
 * @returns 
 */
 export const editSysConfig = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/agent/config',
            method: 'PUT',
            data: params
        }).then(res => {
            resolve(res.data)
        }).catch(error => {
            reject(error)
        })
    })
}

/**
 * 删除代理配置
 * @param {*} params 
 * @returns 
 */
 export const delSysConfig = (id) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/agent/config/' + id,
            method: 'DELETE'
        }).then(res => {
            resolve(res.data)
        }).catch(error => {
            reject(error)
        })
    })
}
